package com.cn.qgx428.lazydiary.ui.fragment


import android.support.v4.app.Fragment
import android.view.View
import android.widget.TextView

import com.cn.qgx428.lazydiary.R
import com.cn.qgx428.lazydiary.local.LAMessege
import com.cn.qgx428.lazydiary.local.LAction
import com.cn.qgx428.lazydiary.local.LActionWacher
import com.cn.qgx428.lazydiary.local.LManager
import com.cn.qgx428.lazydiary.ui.timeline.T_Bill
import com.cn.qgx428.lazydiary.ui.timeline.T_Diary
import com.cn.qgx428.lazydiary.ui.timeline.T_Stikynote
import com.cn.qgx428.lazydiary.ui.timeline.T_TOP
import kotlinx.android.synthetic.main.timeline_stikynote.*


/**
 * A simple [Fragment] subclass.
 */
class TimeLineFragment : BaseFragment(), LActionWacher {

    lateinit var stKnigh: T_Stikynote
    lateinit var tKnigh : T_TOP
    lateinit var bKnigh : T_Bill
    lateinit var dKnigh : T_Diary

    override fun getLayoutId() = R.layout.fragment_time_line

    override fun initView() {
        LManager.newInstance().register(this, LAction.DB_DELETE_STICK_NOTE)
        LManager.newInstance().register(this, LAction.DB_UPDATE_STICK_NOTE)
        LManager.newInstance().register(this, LAction.DB_UPDATE_BILL)
        LManager.newInstance().register(this, LAction.ACTION_LOGIN)
        LManager.newInstance().register(this, LAction.ACTION_CREATE_DIARY)
//        val txt: TextView = mView?.findViewById(R.id.timeline_stikynote_txt)!!
//        txt.text = "111"
        stKnigh = T_Stikynote(activity, mView)
        tKnigh = T_TOP(activity, mView)
        bKnigh = T_Bill(activity, mView)
        dKnigh = T_Diary(activity, mView)
    }

    override fun onTrigger(action: String, msg: LAMessege) {
        when(action){
            LAction.DB_UPDATE_STICK_NOTE,LAction.DB_DELETE_STICK_NOTE->{
                stKnigh.onDataChange()
            }
            LAction.DB_UPDATE_BILL->{
                bKnigh.onDataChange()
            }
            LAction.ACTION_CREATE_DIARY->{
                dKnigh.onDataChange()
            }
            LAction.ACTION_LOGIN->{
                dKnigh.onDataChange()
            }
        }
    }

}// Required empty public constructor
